using System;
using System.Collections.Generic;

namespace Nyanimals
{
	public class CObjectStateMachine
	{
		CBaseObject owner;
		
		Dictionary<string, CObjectBaseState> objectStates;
		
		CObjectBaseState curState;
		string prevState;
		
		public CBaseObject Owner
		{
			get { return owner;}
		}
		
        public CObjectBaseState CurState
        {
            get { return curState;}
        }
        
		public CObjectStateMachine(CBaseObject obj)
		{
			curState = null;
			owner = obj;
			objectStates = new Dictionary<string, CObjectBaseState>();
		}
		
		public void CreateState(CObjectBaseState state)
		{
			state.StateMachine = this;
			objectStates.Add(state.StateName, state);
		}
		
		public void ChangeState(string szName)
		{
			if(curState != null)
			{
				curState.Exit();
				prevState = curState.StateName;
			}
			
			curState = objectStates[szName];
			curState.Enter();
		}
		public void ReturnState(string szName)
		{
			ChangeState(prevState);
		}
		
		public void Input()
		{
			if(curState == null)
			{
				return;
			}
			curState.Input();
		}
		
		public void Update(float deltaTime)
		{
			if(curState == null)
			{
				return;
			}
			curState.Update(deltaTime);
		}
		
		
	}
}

